package com.zlx.xbhy.controller;

import com.zlx.xbhy.entity.Result;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * @ClassName CommonController
 * @Description TODO
 * @Author Edward
 * @Date 2020/11/22 14:43
 */
@RestController
@RequestMapping("common")
public class CommonController {
    @RequestMapping("/sibar")
    public ModelAndView sibar(){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("/html/common/sibar.html");
        return modelAndView;
    }

    @RequestMapping("/header")
    public ModelAndView header(){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("/html/common/header.html");
        return modelAndView;
    }

    @GetMapping("clearSession")
    public Result clearSession(HttpSession session, HttpServletResponse response, HttpServletRequest request){
        session.removeAttribute("loginUser");
        Cookie cookie = new Cookie("loginUser", null);
        cookie.setPath("/");
        //最大7天
        cookie.setMaxAge(0);
        response.addCookie(cookie);
        return new  Result("清除完成！");
    }
}
